<?php

namespace common\modules\ad\models\backend;

use common\widgets\ActiveForm;
use common\widgets\DateTimePicker;
use common\widgets\Form;
use common\widgets\SelectUserWidget;
use Yii;

/**
 * This is the form model class for model "Position".
 */
class PositionForm extends Position
{

    /**
     * @inheritdoc
     */
    public $isNewRecord;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return parent::rules();
    }

    const SCENARIO_CREATE = 'admin-create';
    const SCENARIO_UPDATE = 'admin-update';

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        return [
            'admin-create' => [
                'id',
                'name',
                'ad_width',
                'ad_height',
                'description',
                'template',
                'created_at',
                'updated_at',
                'created_by',
                'updated_by',
            ],
            'admin-update' => [
                'id',
                'name',
                'ad_width',
                'ad_height',
                'description',
                'template',
                'created_at',
                'updated_at',
                'created_by',
                'updated_by',
            ],
        ];
    }

    /**
     * 返回当前表单的名称
     *
     * @return string
     */
    public function classLabelName()
    {
        return Yii::t('backend/ad', 'Position');
    }

    /**
     * 列表定义
     *
     * @param ActiveForm|Form $form
     * @param                 $model PositionForm
     * @param mixed           $extra
     * @return array
     * @throws \yii\web\ServerErrorHttpException
     */
    public function formRows(&$form, $model, $extra)
    {
        return [
            [
                'columns'    => 3,
                'attributes' => [

                    'name' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'ad_width' => [
                        'type' => Form::INPUT_TEXT,
                    ],

                    'ad_height' => [
                        'type' => Form::INPUT_TEXT,
                    ],
                ],
            ],
            [
                'columns'    => 1,
                'attributes' => [

                    'description' => [
                        'type' => Form::INPUT_TEXTAREA,
                        'options' => [
                            'rows' => '3',
                        ],
                    ],

                    'template' => [
                        'type' => Form::INPUT_TEXTAREA,
                        'options' => [
                            'rows' => '6',
                        ],
                    ],
                ],
            ],
            [
                'columns' => 4,
                'attributes' => [

                    'created_at' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => DateTimePicker::className(),
                        'options' => [
                            'type' => DateTimePicker::TYPE_INPUT,
                            'options' => ['disabled' => 'disabled'],
                        ],
                    ],

                    'updated_at' => [
                        'type'        => Form::INPUT_WIDGET,
                        'widgetClass' => DateTimePicker::className(),
                        'options' => [
                            'type' => DateTimePicker::TYPE_INPUT,
                            'options' => ['disabled' => 'disabled'],
                        ],
                    ],

                    'created_by' => [
                        'type' => Form::INPUT_WIDGET,
                        'widgetClass' => SelectUserWidget::className(),
                        'options' => [
                            'isStatic' => true,
                        ],
                    ],
                    'updated_by' => [
                        'type' => Form::INPUT_WIDGET,
                        'widgetClass' => SelectUserWidget::className(),
                        'options' => [
                            'isStatic' => true,
                        ],
                    ],
                ],
            ],
        ];
    }

}
